<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-01-30
 * Time: 10:11
 */

namespace app\index\controller;


use app\common\controller\HomeBase;
use app\common\model\Demandcardingm;
use think\Cache;


class Demandcarding extends HomeBase
{
    /**
     * 前端  用户免费提交项目需求
     */
    public function addDemand()
    {
        if (request()->isPost()) {
            $params = input();
            $validate_result = $this->validate($params, 'Wdemand');
            if ($validate_result !== true) {
                return  json(['code' => 300, 'msg' => $validate_result]);
            }
//            if (Cache::get($params['dc_phone']) != $params['verify']) {
//                return json(['code' => 302, 'msg' => '手机验证码错误']);
//            }
            if (mb_strlen($params['dc_content'], 'UTF8') > 200) {
                return json(['code' => 302, 'msg' => '需求描述不能超过200字']);
            }
            $status =  Demandcardingm::addDemand($params);
            if ($status) {
                return json(['code' => 200, 'msg' => '添加成功']);
            } else {
                return json(['code' => 300, 'msg' => '添加失败']);
            }
        } else {
            return json(['code' => 300, 'msg' => '请求方式错误']);
        }
    }
}